VPATH = src include  # 添加文件搜索目录
CC = cc  # 编译器
CFLAGS = -I include  # 添加.h文件搜索目录
LDFLAGS = -lm  # 动态链接库 math

build: objs/ping

objs/ping: objs/ping.o objs/icmp.o objs/vars.o  objs/tool.o
	$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ 	

objs/ping.o: ping.c icmp.h
	$(CC) $(CFLAGS) -c $< -o $@

objs/icmp.o: icmp.c icmp.h tool.h vars.h
	$(CC) $(CFLAGS) -c $< -o $@

objs/vars.o: vars.c
	$(CC) $(CFLAGS) -c $<  -o $@

objs/tool.o: tool.c
	$(CC) $(CFLAGS) -c $< -o $@

.PHONY: clean install
clean:
	rm -rf objs/*

install: build
	test -d '/usr/local/cping/bin' \
		|| mkdir -p '/usr/local/cping/bin'

	cp objs/ping  '/usr/local/cping/bin/cping'
	rm -rf /usr/bin/cping && ln -s /usr/local/cping/bin/cping  /usr/bin/cping



